Repository navigation
Conversation
After a relaunch, the library waits 10 s for the result of a task that finished while the app was not running. When none came, it deleted the task's key and sent the request again as a new attempt. A late result of the first attempt was then dropped, a 2xx included, and the second send ran to the end. Now the grace marks the old keys superseded instead of deleting them. A late accepted result completes the entry with the first attempt's response, and settle cancels the new attempt's task. A late failure or cancel of the old attempt is dropped and does not disturb the new one. settle (and the relaunch repair of a lost settle) removes an entry's superseded keys of older attempts, so the task map does not grow. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…g request The relaunch grace kept the old attempt's key as superseded, and settle removed only keys of the same generation with a lower attempt. A key stayed when the entry settled inside the grace's own re-issue, or when a different body replaced the entry. A later use of the id, which starts again at generation 1, could then be completed by the old late result. The settle cleanup also removed superseded keys of tasks that reconcile had cancelled, so their cancel callback could reach a later use of the id as a system cancel and send it twice. Now a kept key has its own purpose, lateResult. It is handled like superseded when a late result is evaluated. Reconcile turns it into superseded when it finds the task live, because the task then owes a cancel callback. Every lateResult key of an id is removed when the id settles, is forgotten (ack or cancel of a settled row), or gets a different body. Keys of other purposes stay until their callback. A simple request's outcome now carries the request id of the attempt whose result settled it, as the chunked path already does. The late-result tests move to CoordinatorLateResultTests. Each late failure kind gets its own kept key. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The copy of the completing task's request id into the entry now runs only for an accepted result, so a result that does not settle the entry as completed never changes its request id. taskWillBegin, taskProgress and replaceBackgroundTasks now check isOutdated, so a lateResult key is treated like a superseded one there. No task holds a lateResult key in those paths today: reconcile changes a live task's lateResult key to superseded. The CHANGELOG now says that a superseded or pause key of the waited attempt stays until its cancel callback, where the end of the wait used to delete it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
After a relaunch, iOS replays the results of uploads that finished while the app was not running. The library waits 10 s (
graceMs) for each one. When no result came in that time, it deleted the old task's key and sent the request again as a new attempt (task B).When the first attempt's result then arrived, the library could not match it to the entry any more, so it dropped it. That included a 2xx. B then ran to the end. So a first attempt that the server accepted was always followed by a second send, which can store a second copy on the server.
What changes
withoutTask(QueueCoordinator+Reconcile.swift) marks the old attempt's keyslateResultinstead of deleting them. A key already markedsupersededorpausekeeps its purpose, because its task may still owe a cancel callback. The re-send is unchanged.taskCompletedLockedtreatslateResultlikesuperseded:settlecancels B;lateResultkey. If it finds one live, it cancels it and changes the key tosuperseded, because that task now owes a cancel callback. A task that iOS lists as finished is not live, so reconcile neither adopts nor cancels it.lateResultkey of an id is removed when the id settles, when its row is forgotten (the ack that forgets it, orcancel()on a settled row), and when a same-idmutate()gives it a different body. This covers any attempt and any generation. Before, the end of the 10 s wait deleted every key of the waited attempt, including keys of tasks the library had cancelled (supersededorpause). Now such a key stays until its task's cancel callback removes it, or until the row is gone and the next launch prunes it.requestIdof an outcome belong to the same request.attemptsstill counts every attempt.sequenceDiagram participant D as iOS daemon participant L as Library participant S as Server Note over D,S: Attempt 1 finished while the app was not running L->>L: Relaunch: wait 10 s for attempt 1's result L->>L: No result: keep attempt 1's key as a late-result key L->>D: Create task B (attempt 2) D-->>L: Late result of attempt 1: 201 L->>L: Complete the entry with attempt 1's response and request id L->>D: Cancel task B Note over D,S: If B had not started, the server gets one requestBehavior change
acceptrules allow) now completes an entry that earlier versions left running and sent again. The app gets the first attempt's response. The late result emits anattemptevent for attempt 1 with itsX-Request-Id.requestId(iOS, simple requests). The settled outcome'srequestIdis now the id of the attempt whose result settled the entry. Before, it was the last attempt's, which after a late result could be a task that was cancelled before it began.lastRequestId, which is set when each attempt starts. A simple request on Android runs one attempt at a time, so its last attempt is the one that settled it. A chunked request runs parts at the same time, so itsrequestIdis the last part attempt that started, which can be another part.Meta.requestIddoc insrc/types.tsand the README say this per platform. The CHANGELOG has the entry under "Unreleased", and the README "Relaunch" paragraph describes the late result.What it does not fix
expiresAtduring the wait;What Apple documents and what is observed. Apple documents that the session replays
didCompleteWithErrorfor finished tasks after the app creates the session again, and that a cancelled task always gets a callback. Apple does not document how late a replayed result can arrive, or that a task listed as finished still gets its callback. One observation (RAD-17385) shows the library re-sent a task that iOS listed as finished. This change does not depend on either undocumented point: it only keeps a result that does arrive.Tests
24 new tests in
CoordinatorLateResultTests, and two updated tests inCoordinatorRelaunchTests. They cover:cancel()of a settled row, and at a different-body replace.Each part of the fix was broken on purpose, and at least one test failed each time.
Checks run locally, all exit 0:
yarn lint:ci,yarn typecheck,yarn test(305 tests),swift testinios(407 tests, 1 perf test skipped by design), the Android unit tests (424 tests).Two independent reviews were applied. Part of RAD-17385.
🤖 Generated with Claude Code